<?php

	function check_username_pass($Username, $Password)
	{
		$Password =  md5($Password);
		$sql = "SELECT * FROM users WHERE Username = '$Username' AND Password = '$Password'";		
		return mysql_query($sql);
	}
	
	function danhsach_hotro()
	{
		$sql = "SELECT * FROM ho_tro";
		return mysql_query($sql);
	}
	function them_hotro($ho_ten,$loai_ho_tro,$nick_chat,$trang_thai)
	{
		$sql = "INSERT INTO ho_tro(`ho_ten`,`loai_ho_tro`,`nick_chat`,`trang_thai`) VALUES('$ho_ten','$loai_ho_tro','$nick_chat','$trang_thai')";
		return mysql_query($sql);
	}
	
	function xem_baiviet()
	{
		$sql= "SELECT * FROM baiviet";
		return  mysql_query($sql);
	}
	function xoa_baiviet($id)
	{
		$sql= "DELETE FROM baiviet WHERE id = '$id'";
		return  mysql_query($sql);
	}
	
	function them_baiviet($id,$title,$sumary,$content,$nguoiviet)
	{
		$sql = "INSERT INTO baiviet(`id`,`title`,`sumary`,`content`,`nguoiviet`) VALUES('$id','$title','$sumary','$content','$nguoiviet')";
		return mysql_query($sql);
	}
/****************************************************************************/
    function danhsach_sp()
    {
        $sql = "SELECT sanpham.idSP,TenSP,TenCL,TenLoai,MoTa,UrlHinh,sanpham.New FROM sanpham,chungloai,loaisp WHERE sanpham.idCL=chungloai.idCL and sanpham.idLoai=loaisp.idLoai order by sanpham.idSP DESC";
        return mysql_query($sql);
    }
    function danhsachsp($idSP)
	{
		return mysql_query($sql);
		$sql = "SELECT sanpham.idSP,TenSP,TenCL,TenLoai,MoTa,UrlHinh,sanpham.New FROM sanpham,chungloai,loaisp WHERE sanpham.idSP = $idSP";
	}
    
    function danhsach_sp_xoa()
    {
        $idSP  = $_GET['idSP'];
        settype($idSP, "int");
        $sql = "DELETE FROM sanpham WHERE idSP=$idSP";
        return mysql_query($sql);
    }
    
    function danhsach_them_sp($idSP,$TenSP, $idCL, $idLoai, $MoTa, $Gia, $UrlHinh, $baiviet, $GhiChu, $SoLuongTon, $New)
    {
     /*   settype($ChungLoai, "int");
		settype($LoaiSP, "int");
		settype($Gia,"int");
		settype($SoLuongTon,"int");
		settype($New, "int");
		settype($idSP, "int");     */
        $sql = "INSERT INTO sanpham(`idSP`,`idLoai`,`idCL`,`TenSP`,`MoTa`,`Gia`,`UrlHinh`,`baiviet`,`SoLuongTonKho`,`GhiChu`,`New`) VALUES('$idSP','$idLoai','$idCL','$TenSP','$MoTa','$Gia','$UrlHinh','$baiviet','$SoLuongTon','$GhiChu','$New')";
        return mysql_query($sql);
    }
    
   
    
   
  function UpdateSanPham($idSP,$TenSP, $idCL, $idLoai, $MoTa, $Gia, $UrlHinh, $baiviet, $SoLuongTon,$GhiChu, $New)
  {      
      
    settype($ChungLoai, "int");
    settype($LoaiSP, "int");
    settype($Gia,"int");
    settype($SoLuongTon,"int");
    settype($New, "int");
    settype($idSP, "int");
    
$sql = "UPDATE sanpham set idLoai = $idLoai,idCL = $idCL,TenSP = '$TenSP', MoTa = '$MoTa',Gia=$Gia,UrlHinh='$UrlHinh',baiviet='$baiviet',SoLuongTonKho=$SoLuongTon,
         GhiChu='$GhiChu',New=$New WHERE idSP = $idSP ";
         return mysql_query($sql);
  }
    
  function ChiTietSanPham($idSP)
  {
      $sql ="SELECT * FROM sanpham WHERE idSP = $idSP";
      return mysql_query($sql);
  }
   /*
     * Chủng loai
     */
     function ChungLoai()
    {
        $sql = "SELECT * FROM chungloai";
        return mysql_query($sql);
    }
    function Chungloai_xoa()
    {
       $idCL=$_GET['idCL'];
       settype($idCL, "int");
       $sql = "DELETE FROM chungloai WHERE idCL=$idCL ";
       return mysql_query($sql);
           
    }
    function ChungLoai_them($TenCL,$ThuTu)
    {
     
        settype($ThuTu,"int");
        $sql = "INSERT INTO chungloai VALUES(null,'$TenCL',$ThuTu)";
        mysql_query($sql);
    }
    function ChungLoai_update($idCL)
    {
        $idCL = $_GET['idCL'];
        $TenCL = $_POST['TenCL'];
        $ThuTu = $_POST['ThuTu'];
         
        settype($ThuTu,"int");
        $sql = "UPDATE chungloai SET TenCL='$TenCL', ThuTu=$ThuTu WHERE idCL = $idCL";
        mysql_query($sql);
    }
       
    function Chungloai_chitiet($idCL)
    {
        
        $sql = "SELECT * FROM chungloai WHERE idCL=$idCL";
        return mysql_query($sql);
    }
    /*
     * Loại Sản phẩm
     */
    function LoaiSanPham()
    {
        $sql = "SELECT idLoai,chungloai.TenCL, TenLoai,loaiSP.ThuTu FROM loaisp, chungloai WHERE loaisp.idCL=chungloai.idCL";
        return mysql_query($sql);
    }
    
	/*function Loaisp_sapxep()
	{
		
	}*/
    function LoaiSP($idLoai) 
    {
        if(isset($_GET['idLoai']))
            $idLoai = $_GET['idLoai'];
        $sql = "SELECT *FROM loaisp WHERE idLoai= $idLoai ";
        return mysql_query($sql);
    }
    function _LoaiSP($idCL) 
    {
        
        $sql = "SELECT *FROM loaisp WHERE idCL= $idCL ";
        return mysql_query($sql);
    }
   
     function loai_xoa($idLoai)
    {
       $sql = "DELETE FROM loaisp WHERE idLoai=$idLoai ";
       return mysql_query($sql);
           
    }
    function loai_them($TenLoai,$idCL,$ThuTu)
    {
      
        
        settype($idCL, "int");
        settype($ThuTu, "int");
        
        $sql ="INSERT INTO loaisp VALUES(null,$idCL,'$TenLoai',$ThuTu)";
        return mysql_query($sql);
    }
    function loai_update($idLoai,$idCL,$TenLoai,$ThuTu)
    {
		
        settype($idCL, "int");
        settype($ThuTu, "int");
        
        $sql = "UPDATE loaisp SET idCL=$idCL,TenLoai='$TenLoai',ThuTu=$ThuTu WHERE idLoai=$idLoai ";
        return mysql_query($sql);
    }
    
   /*
    * thuoc tinh
    */
    function sanpham_thuoctinh()
    {
         $sql = "SELECT * FROM sanpham_thuoctinh";
         return mysql_query($sql);
    }
    
     function ChitietThuocTinh($idSP)
    {
 
         $idSP = $_GET['idSP'];
        $sql = "SELECT * FROM sanpham_thuoctinh WHERE idSP = $idSP";
        return mysql_query($sql);
    }
    
    function Themthuoctinh($idSP,$tinhnangnoibac,$mayanh,$dactinhmayanh,$mayanhphu,$videocall,$quayphim,$xemphim,$nghenhac,
                            $fmradio,$xemtivi,$ghiam,$ghiamcuocgoi,$ghiamfm,$java,$trochoi,$ketnoitv,
                            $ungdungvanphong,$ungdungkhac,$nhacchuongloai,$nhacchuongloangoai,$nhacchuongbaorung,$nhacchuongjacktainghe,
                            $bonhotrong,$bonhoram,$bonhovixuly,$bonhothenhongoai,$bonhotoida,$tinnhan)
    {
        $sql = "INSERT INTO sanpham_thuoctinh VALUES(null,'$idSP','$tinhnangnoibac','$mayanh','$dactinhmayanh','$mayanhphu','$videocall','$quayphim','$xemphim','$nghenhac',
                            '$fmradio','$xemtivi','$ghiam','$ghiamcuocgoi','$ghiamfm','$java','$trochoi','$ketnoitv',
                            '$ungdungvanphong','$ungdungkhac','$nhacchuongloai','$nhacchuongloangoai','$nhacchuongbaorung','$nhacchuongjacktainghe',
                            '$bonhotrong','$bonhoram','$bonhovixuly','$bonhothenhongoai','$bonhotoida','$tinnhan')";
        return mysql_query($sql);
    }
?>

